home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AEWIN100.ARJ / VIDBUF.CC < prev    next >
C/C++ Source or Header  |  1991-10-28  |  3KB  |  168 lines

  1. /**********************************************************************
  2.  *  
  3.  *  NAME:           vidbuf.cpp
  4.  *  
  5.  *  DESCRIPTION:    methods for video buffer class
  6.  *  
  7.  *  copyright (c) 1990 J. Alan Eldridge
  8.  * 
  9.  *  M O D I F I C A T I O N   H I S T O R Y
  10.  *
  11.  *  when        who                 what
  12.  *  -------------------------------------------------------------------
  13.  *  11/25/90    J. Alan Eldridge    created
  14.  *  
  15.  *********************************************************************/
  16.  
  17. #include    "w.h"
  18.  
  19. void
  20. vidbuf::open(
  21.     int yUl,    
  22.     int xUl,
  23.     int yLr,
  24.     int xLr)
  25. {
  26.     int r = yLr - yUl + 1;
  27.     int c = xLr - xUl + 1;
  28.     
  29.     state = ERR;
  30.  
  31.     //  check for bad args, or failure to init the system
  32.     if (!r || !c || yUl < 0 || xUl < 0 || yLr >= vid_ROWS
  33.             || xLr >= vid_COLS || initscr(LASTMODE) != OK)
  34.         return;
  35.  
  36.     //  allocate buffer and, if ok, init member vars
  37.     if (pbuf = new vidchr [ r * c ]) {
  38.         state = OK;
  39.         yCur =
  40.         xCur = 0;
  41.         rows = r;
  42.         cols = c;
  43.         yOrg = yUl;
  44.         xOrg = xUl;
  45.     }
  46. }
  47.  
  48. //  free up memory, etc.
  49.  
  50. void
  51. vidbuf::close()
  52. {
  53.     if (state == OK) {
  54.         state = ERR;
  55.         delete [ rows * cols ] pbuf;
  56.     }
  57. }
  58.         
  59. //  clear part of a line
  60.  
  61. void
  62. vidbuf::clrline(
  63.     int row,
  64.     int left,
  65.     int right,
  66.     int chr,
  67.     int att)
  68. {
  69.     if (state != OK)
  70.         return;
  71.         
  72.     int     cnt = right - left + 1;
  73.     vidchr  *dst = vidptr(row, left);
  74.     
  75.     for (int n = 0; n < cnt; n++)
  76.         dst[n].put(chr, att);
  77. }        
  78.  
  79. //  clear a rectangular area
  80.  
  81. void
  82. vidbuf::clear(
  83.     int yul,
  84.     int xul,
  85.     int ylr,
  86.     int xlr,
  87.     int chr,
  88.     int att)
  89. {
  90.     if (state != OK) 
  91.         return;
  92.     
  93.     //  keep in bounds
  94.     if (ylr >= rows) ylr = rows-1;
  95.     if (xlr >= cols) xlr = cols-1;
  96.  
  97.     //  do the fills
  98.     int     cnt = xlr - xul + 1;
  99.     vidchr  *dst = vidptr(yul, xul);
  100.     
  101.     for (int row = yul; row <= ylr; row++, dst += cols) {
  102.         for (int n = 0; n < cnt; n++)
  103.             dst[n].put(chr, att);
  104.     }
  105. }
  106.  
  107. //  update to Screen and maybe video display
  108.  
  109. void
  110. vidbuf::display(int row, int col, int cnt, int vflag)
  111. {
  112.     if (this != &Screen)
  113.         Screen.write(yOrg+row,xOrg+col,vidptr(row,col),cnt);
  114.     if (vflag)
  115.         vid_write(yOrg+row,xOrg+col,vidptr(row,col),cnt); 
  116. }
  117.  
  118. void
  119. vidbuf::setcursor(int vflag)
  120. {
  121.     if (this != &Screen)
  122.         Screen.setpos(yCur+yOrg,xCur+xOrg);
  123.     if (vflag)
  124.         vid_setcpos(yCur+yOrg,xCur+xOrg); 
  125. }
  126.  
  127. //  update to display screen (entire buffer)
  128.  
  129. void
  130. vidbuf::refresh(int vflag)
  131. {
  132.     if (state != OK) return;
  133.  
  134.     for (int r = 0; r < rows; r++) {
  135.         display(r, 0, cols, vflag);
  136.     }
  137.     setcursor(vflag);
  138. }
  139.     
  140. //  check if pointing device is in window
  141. //  if so, modify coordinates so they are window relative
  142.  
  143. int
  144. vidbuf::inwindow(
  145.     int &y,
  146.     int &x)
  147. {
  148.     if (y >= yOrg && y < yOrg + rows
  149.             && x >= xOrg && x < xOrg + cols) {
  150.         y -= yOrg;
  151.         x -= xOrg;
  152.         return TRUE;
  153.     } else
  154.         return FALSE;
  155. }
  156.  
  157. //  copy from Screen object ...
  158. //  a refresh will restore the screen
  159.  
  160. void
  161. vidbuf::cpscreen()
  162. {
  163.     for (int y = yOrg, r = 0; r < rows; y++, r++)
  164.         Screen.read(y, xOrg, vidptr(r, 0), cols);
  165.     Screen.getpos(yCur, xCur);
  166.     yCur -= yOrg; xCur -= xOrg;
  167. }
  168.